


function formatNumber(n) { // 1转换成01
  n = n.toString()
  return n[1] ? n : '0' + n
}

/**
 * 格式化时间
 */

function getCurrentDate (val) { //处理当前时间转换成各种格式
  var today = new Date(val) //时间对象
  var year = today.getFullYear() //年
  var month = today.getMonth() + 1 //月
  var day = today.getDate() //日
  var week = today.getDay() //天
  var hour = today.getHours() //时
  var minute = today.getMinutes() //分
  var second = today.getSeconds() //秒

  function getFullDate() { //2018/01/01
    return [year, month, day].map(formatNumber).join('-')
  }

  function getYearMonth() { //2018/01
    return [year, month].map(formatNumber).join('-')
  }

  function getYear() { //2018
    return year
  }

  function getMonthDay() { //01/01
    return [month, day].map(formatNumber).join('-')
  }

  function getFullHourMinute() { //09:00
    return [hour, minute].map(formatNumber).join(':')
  }

  function getFullTime() { //09:00:00
    return [hour, minute, second].map(formatNumber).join(':')
  }

  function getMonth() { //09
    return formatNumber(month)
  }

  function getDay() { //09
    return formatNumber(day)
  }

  function getHour() { //09
    return formatNumber(hour)
  }

  return {
    getFullDate,
    getYear,
    getYearMonth,
    getMonthDay,
    getFullHourMinute,
    getFullTime,
    getMonth,
    getDay,
    getHour,
  }
}

/**
 * 格式化时间
 */

function formatData (val) {
  var year = getCurrentDate(val).getYear()
  var mouth = getCurrentDate(val).getMonth()
  var day = getCurrentDate(val).getDay()
  return [year, mouth, day]
}

export  default {
  getCurrentDate,
  formatData
}
